﻿/***  File Header  ************************************************************/
/**
*  Dic.h
*
* P4thディクショナリ
*  shozo fukuda
*    作成 Sat Mar 31 23:27:28 2012
*    修正 $Date:$
* System  Generic <br>
*
*******************************************************************************/
#ifndef _DIC_H
#define _DIC_H

/*******************************************************************************
* IMPORTS:
*******************************************************************************/
#include "charm.h"
#include "P4th.h"

/*******************************************************************************
* CONSTANT:
*******************************************************************************/
enum {
	P_UNKNOWN        =    0,
	P_LIT            =    1,
	P_COLON          =    4,
	P_SEMICOLON      =    7,
	P_IMMEDIATE      =   10,
	P_CONSTANT       =   13,
	P_VARIABLE       =   16,
	P_DUP            =   19,
	P_QDUP           =   22,
	P_DROP           =   25,
	P_SWAP           =   28,
	P_OVER           =   31,
	P_ROT            =   34,
	P_PICK           =   37,
	P_2DUP           =   40,
	P_2DROP          =   43,
	P_2OVER          =   46,
	P_2SWAP          =   49,
	P_DEPTH          =   52,
	P_DOT            =   55,
	P_EMIT           =   58,
	P_SPACE          =   61,
	P_SPACES         =   64,
	P_CR             =   67,
	P_DOT_2HEX       =   70,
	P_DOT_4HEX       =   73,
	P_DOT_8HEX       =   76,
	P_FETCH          =   79,
	P_STORE          =   82,
	P_PLUS_STORE     =   85,
	P_C_FETCH        =   88,
	P_C_STORE        =   91,
	P_ADD            =   94,
	P_SUB            =   97,
	P_MUL            =  100,
	P_DIV            =  103,
	P_MOD            =  106,
	P_INCR           =  109,
	P_DECR           =  112,
	P_NEGATE         =  115,
	P_ABS            =  118,
	P_MIN            =  121,
	P_MAX            =  124,
	P_AND            =  127,
	P_OR             =  130,
	P_XOR            =  133,
	P_EQ             =  136,
	P_LT             =  139,
	P_GT             =  142,
	P_ZEQ            =  145,
	P_ZLT            =  148,
	P_ZGT            =  151,
	P_TO_R           =  154,
	P_FROM_R         =  157,
	P_R_FETCH        =  160,
	P_0BRANCH        =  161,
	P_BRANCH         =  162,
	P_IF             =  165,
	P_ELSE           =  168,
	P_THEN           =  171,
	P_BEGIN          =  174,
	P_UNTIL          =  177,
	P_WHILE          =  180,
	P_REPEAT         =  183,
	P_DO             =  186,
	P_XDO            =  187,
	P_LOOP           =  190,
	P_XLOOP          =  191,
	P_PLOOP          =  194,
	P_XPLOOP         =  195,
	P_I              =  198,
	P_J              =  201,
	P_EXIT           =  204,
	P_VERSION        =  207,
	P_DUMPNEW        =  210,
};

enum {
	S_UNKNOWN        =    0 | F_IMMEDIATE,
	S_LIT            =    1,
	S_COLON          =    2 | F_IMMEDIATE,
	S_DOCOL          =    3,
	S_SEMICOLON      =    4 | F_IMMEDIATE,
	S_IMMEDIATE      =    5 | F_IMMEDIATE,
	S_CONSTANT       =    6,
	S_DOCONST        =    7,
	S_VARIABLE       =    8,
	S_DOVAR          =    9,
	S_DUP            =   10,
	S_QDUP           =   11,
	S_DROP           =   12,
	S_SWAP           =   13,
	S_OVER           =   14,
	S_ROT            =   15,
	S_PICK           =   16,
	S_2DUP           =   17,
	S_2DROP          =   18,
	S_2OVER          =   19,
	S_2SWAP          =   20,
	S_DEPTH          =   21,
	S_DOT            =   22,
	S_EMIT           =   23,
	S_SPACE          =   24,
	S_SPACES         =   25,
	S_CR             =   26,
	S_DOT_2HEX       =   27,
	S_DOT_4HEX       =   28,
	S_DOT_8HEX       =   29,
	S_FETCH          =   30,
	S_STORE          =   31,
	S_PLUS_STORE     =   32,
	S_C_FETCH        =   33,
	S_C_STORE        =   34,
	S_ADD            =   35,
	S_SUB            =   36,
	S_MUL            =   37,
	S_DIV            =   38,
	S_MOD            =   39,
	S_INCR           =   40,
	S_DECR           =   41,
	S_NEGATE         =   42,
	S_ABS            =   43,
	S_MIN            =   44,
	S_MAX            =   45,
	S_AND            =   46,
	S_OR             =   47,
	S_XOR            =   48,
	S_EQ             =   49,
	S_LT             =   50,
	S_GT             =   51,
	S_ZEQ            =   52,
	S_ZLT            =   53,
	S_ZGT            =   54,
	S_TO_R           =   55,
	S_FROM_R         =   56,
	S_R_FETCH        =   57,
	S_0BRANCH        =   58,
	S_BRANCH         =   59,
	S_IF             =   60 | F_IMMEDIATE,
	S_ELSE           =   61 | F_IMMEDIATE,
	S_THEN           =   62 | F_IMMEDIATE,
	S_BEGIN          =   63 | F_IMMEDIATE,
	S_UNTIL          =   64 | F_IMMEDIATE,
	S_WHILE          =   65 | F_IMMEDIATE,
	S_REPEAT         =   66 | F_IMMEDIATE,
	S_DO             =   67 | F_IMMEDIATE,
	S_XDO            =   68,
	S_LOOP           =   69 | F_IMMEDIATE,
	S_XLOOP          =   70,
	S_PLOOP          =   71 | F_IMMEDIATE,
	S_XPLOOP         =   72,
	S_I              =   73,
	S_J              =   74,
	S_EXIT           =   75 | F_IMMEDIATE,
	S_VERSION        =   76,
	S_DUMPNEW        =   77 | F_IMMEDIATE,
};

const long FENCE = 208;

/*---    マクロ定義    ---*/
#define STATE     (p4th->iState)

#define IP        (p4th->iIP)
#define W         (p4th->iW)

#define TOS       (p4th->At(1))
#define S2        (p4th->At(2))
#define S3        (p4th->At(3))
#define S4        (p4th->At(4))
#define S(d)      (p4th->At(d))
#define DEPTH     (p4th->Depth())

#define RTOS      (p4th->RAt(1))
#define R2        (p4th->RAt(2))
#define R3        (p4th->RAt(3))
#define R4        (p4th->RAt(4))

#define PUSH(x)   (p4th->Push(x))
#define POP()     (p4th->Pop())
#define RPUSH(x)  (p4th->RPush(x))
#define RPOP()    (p4th->RPop())

#define CURRENT   (p4th->iCurrent)
#define BUILD(x)  (p4th->Build(x))
#define CODE(a)   (p4th->Memory(a))
#define HERE()    (p4th->Here())
#define OFFS(a)   (p4th->Offs(a))

#define BEG_SELF  (p4th->BegSelf())
#define END_SELF  (p4th->EndSelf())

#endif /* _DIC_H */
